package java_thinking.unit_16;

import java_thinking.net.mindview.util.ConvertTo;
import java_thinking.net.mindview.util.Generated;
import java_thinking.net.mindview.util.RandomGenerator;
import java_thinking.unit_15._15_3.Generator;

import java.util.Arrays;

/**
 * @Desc:   在已排序的数组中查找Arrays.binarySearch()
 * @author: cww
 * @DateTime: 2019/4/10 20:06
 */

public class _7_5_1ArraySearching {
    public static void main(String[] args) {
        Generator<Integer> gen = new RandomGenerator.Integer(1000);
        int[] a = ConvertTo.primitive(Generated.array(new Integer[25],gen));
        Arrays.sort(a);
        System.out.println("sorted: "+Arrays.toString(a));
        while (true) {
            int r = gen.next();
            int location = Arrays.binarySearch(a,r);
            if (location >= 0) {
                System.out.println("Location of "+r+" is "+ location);
                break;
            }
        }
    }
}
